<?php

namespace app\admin\controller\uniwigs;

use app\common\controller\Backend;

/**
 * 规则管理
 *
 * @icon fa fa-circle-o
 */
class Member extends Backend
{
    
    /**
     * CashCodeRule模型对象
     * @var \app\admin\model\Member
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('Member');
		
		
		$form_params =  [
			
			[	
				'zone'=>'add,edit',
				'key'=> 'balance',
				'name'=> '账户余额',
				'form' => 'input',
				'form_type' => 'text',
				'required'=>false
				
			],
			[	
				'zone'=>'add,edit',
				'key'=> 'username',
				'name'=> '姓名',
				'form' => 'input',
				'form_type' => 'text',
				'required'=>true
				
			],
			
			[	
				'zone'=>'add,edit',
				'key'=> 'nickname',
				'name'=> '昵称',
				'form' => 'input',
				'form_type' => 'text'	,
				'required'=>false
			],
			
			[	
				'zone'=>'add,edit',
				'key'=> 'iphone',
				'name'=> '手机',
				'form' => 'input',
				'form_type' => 'text',
				'required'=>true				
			],
			
			[	
				'zone'=>'add,edit',
				'key'=> 'iphone2',
				'name'=> '备用手机',
				'form' => 'input',
				'form_type' => 'text',
				'required'=>false				
			],
			
			[	
				'zone'=>'add,edit',
				'key'=> 'email',
				'name'=> '邮箱',
				'form' => 'input',
				'form_type' => 'text',
				'required'=>false
			],
			
			[	
				'zone'=>'edit',
				'key'=> 'idcard',
				'name'=> '身份证',
				'form' => 'input',
				'form_type' => 'text'	,
				'required'=>false
			],
			[	
				'zone'=>'edit',
				'key'=> 'company',
				'name'=> '公司',
				'form' => 'input',
				'form_type' => 'text'	,
				'required'=>false
			],
			[	
				'zone'=>'edit',
				'key'=> 'address',
				'name'=> '地址',
				'form' => 'input',
				'form_type' => 'text'	,
				'required'=>false
			],
			
			[	
				'zone'=>'add,edit',
				'key'=> 'note',
				'name'=> '备注',
				'form' => 'input',
				'form_type' => 'text'	,
				'required'=>true
			],
			
			
			[	
				'zone'=>'add,edit',
				'key'=> 'status',
				'name'=> '状态',
				'form' => 'radio',
				'form_type' => 'text',
				'selects' => 'statusList',
				'required'=>true
			]
			
			
		];
		
		$this->view->assign("form_params", $form_params);
		
        $this->view->assign("statusList", $this->model->getStatusList());
    }
    
     /**
     * 查看
     */
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax())
        {	
	
			
			
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField'))
            {
                return $this->selectpage();
            }
		
			
			//每个不同model 的 主键 不一致 默认为id 所以这里搜索要指定为 此model 的主键 id_code 
            list($where, $sort, $order, $offset, $limit) = $this->buildparams('id');

			
            $total = $this->model
                    ->where($where)
                    ->order($sort, $order)
                    ->count();
			
			
		
			
            $list = $this->model
                    ->where($where)
                    ->order($sort, $order)
                    ->limit($offset, $limit)
                    ->select();
		
			

            $list = collection($list)->toArray();
            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }
        return $this->view->fetch();
    }

}
